/**
 * InteractiveObject 类是用户可以使用鼠标和键盘与之交互的所有显示对象的抽象基类。
 * @author zzhanglin
 * @returns {InteractiveObject}
 */
InteractiveObject = function()
{
	DisplayObject.call(this);
	this.className="InteractiveObject"; //类名
	this.mouseEnabled = false ; //默认为不支持鼠标事件
	this.doubleClickEnabled =false ; //是否启用了双击
	
	this._mouseIsOver= false; //鼠标是否在此对象上面
};
FLASH.extend(InteractiveObject , DisplayObject); //继承自DisplayObject

/**
 * 鼠标移动
 * @param localX 相对canvas的鼠标坐标位置 
 * @param localY 相对canvas的鼠标坐标位置
 * @param 当前对象是否抛出了mouseMove事件
 */
InteractiveObject.prototype._onMouseMove = function( localX, localY, ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;

	this._mouseX=localX-this._x+this._pivotX ;
	this._mouseY=localY-this._y +this._pivotY ;
	var bool = this.hitTestPoint(this._mouseX,this._mouseY );
	if(bool){
		if(this.hasEventListener(MouseEvent.MOUSE_MOVE))
		{
			var evt = new MouseEvent( MouseEvent.MOUSE_MOVE , true , this._mouseX ,  this._mouseY , 
					ctrlKey, altKey,shiftKey, buttonDown, delta );
			this.dispatchEvent(evt);
		}
		//mouseOver事件 
		this._onMouseOver( ctrlKey, altKey,shiftKey, buttonDown, delta  );
	}else{
		//mouseOut事件
		this._onMouseOut( ctrlKey, altKey,shiftKey, buttonDown, delta  );
	}
	return bool ;
};
/**
 * 鼠标按下
 */
InteractiveObject.prototype._onMouseDown = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;
	
	if(this._mouseIsOver){
		if(this.hasEventListener(MouseEvent.MOUSE_DOWN))
		{
			var evt = new MouseEvent( MouseEvent.MOUSE_DOWN,true ,  this._mouseX ,  this._mouseY , 
					ctrlKey, altKey,shiftKey, buttonDown, delta );
			this.dispatchEvent(evt);
		}
		return true;
	}
	return false;
};
/**
 * 鼠标弹起
 */
InteractiveObject.prototype._onMouseUp = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;
	
	if(this._mouseIsOver){
		if(this.hasEventListener(MouseEvent.MOUSE_UP))
		{
			var evt = new MouseEvent( MouseEvent.MOUSE_UP , true , this._mouseX ,  this._mouseY , 
					ctrlKey, altKey,shiftKey, buttonDown, delta );
			this.dispatchEvent(evt);
		}
		//抛出鼠标点击事件
		this._onMouseClick( ctrlKey, altKey,shiftKey, buttonDown, delta );
		return true;
	}
	return false;
};
/**
 * 鼠标单击
 */
InteractiveObject.prototype._onMouseClick = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;
	if(this.hasEventListener(MouseEvent.CLICK))
	{
		var evt = new MouseEvent( MouseEvent.CLICK ,true ,  this._mouseX ,  this._mouseY , 
				ctrlKey, altKey,shiftKey, buttonDown, delta );
		this.dispatchEvent(evt);
	}
	return true;
};
/**
 * 鼠标在上面
 */
InteractiveObject.prototype._onMouseOver= function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;
	
	if(!this._mouseIsOver){
		this._mouseIsOver = true ;
		if(this.hasEventListener(MouseEvent.MOUSE_OVER))
		{
			var evt = new MouseEvent( MouseEvent.MOUSE_OVER , true , this._mouseX ,  this._mouseY , 
					ctrlKey, altKey,shiftKey, buttonDown, delta );
			this.dispatchEvent(evt);
		}
		return true;
	}
	return false;
};
/**
 * 鼠标移出此对象
 */
InteractiveObject.prototype._onMouseOut = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if(!this.mouseEnabled ) return false ;
	
	if(this._mouseIsOver){
		this._mouseIsOver = false ;
		if(this.hasEventListener(MouseEvent.MOUSE_OUT))
		{
			var evt = new MouseEvent( MouseEvent.MOUSE_OUT ,true ,  this._mouseX ,  this._mouseY , 
					ctrlKey, altKey,shiftKey, buttonDown, delta );
			this.dispatchEvent(evt);
		}
		return true ;
	}
	return false ;
};